package com.six.firstpage.controller.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.six.core.entity.BottomArticle;
import com.six.core.vo.Result;
import com.six.firstpage.service.BottomArticleService;
import com.six.firstpage.vo.SearchVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author:zzh
 * @create: 2023-02-27 19:34
 * @Description:
 */
@Api(value = "firstpage/api/bottomArticle", tags = {"底部链接前端API"})
@RestController
@RequestMapping("firstpage/api/bottomArticle")
//@CrossOrigin
public class ApiBotomArticleController {

    @Autowired
    private BottomArticleService bottomArticleService;

    @GetMapping("/getAllBottomArticle")
    public Result getAllBottomArticle(){
        List<BottomArticle> allBottomArticle = bottomArticleService.getAllBottomArticle();
        return new Result(2000,"前端查询底部文章链接成功",allBottomArticle);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "SearchVo", name = "searchVo", value = "", required = true),
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "current", value = "", required = true),
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "pageSize", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("getBottomArticleByTitle/{current}/{pageSize}")
    public Result getBottomArticleByTitle(@RequestBody SearchVo searchVo, @PathVariable  Integer current, @PathVariable  Integer pageSize){
        Page<BottomArticle> page = bottomArticleService.getBottomArticleByTitle(searchVo.getTitle(), searchVo.getStatus(), current, pageSize);
        return new Result(2000,"查询底部链接成功",page);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "BottomArticle", name = "bottomArticle", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("addBottomArticleByTitle")
    public Result addBottomArticle(@RequestBody BottomArticle bottomArticle){
        Integer integer = bottomArticleService.addBottomArticle(bottomArticle);
        if (integer>0){
            return new Result(2000,"添加底部链接成功");
        }
        return new Result(5000,"添加底部链接失败");
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "BottomArticle", name = "bottomArticle", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "PUT")
    @PutMapping("updateBottomArticle")
    public Result updateBottomArticle(@RequestBody BottomArticle bottomArticle){
        Integer integer = bottomArticleService.updateBottomArticle(bottomArticle);
        if (integer>0){
            return new Result(2000,"修改底部链接成功");
        }
        return new Result(5000,"修改底部链接失败");
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("delBottomArticle/{id}")
    public Result delBottomArticle(@PathVariable String id){
        Integer integer = bottomArticleService.delBottomArticle(id);
        if (integer>0){
            return new Result(2000,"删除底部链接成功");
        }
        return new Result(5000,"删除底部链接失败");
    }

}
